<!DOCTYPE html>
<html lang="ZH-cn">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Test</title>
  <link rel="stylesheet" href="./styles/default.css">
</head>

<body>
  <s-page>
    <main>
      <s-tab onchange="console.log(this.selectedIndex)">
        <!-- <s-tab-item selected="true">
          <s-icon type="add" slot="icon"></s-icon>
          <div slot="text">destination</div>
        </s-tab-item>
        <s-tab-item>
          <s-icon type="search" slot="icon"></s-icon>
          <div slot="text">navigation</div>
        </s-tab-item>
        <s-tab-item>
          <s-icon type="light_mode" slot="icon"></s-icon>
          <div slot="text">container</div>
          <s-badge slot="badge">16</s-badge>
        </s-tab-item>
        <s-tab-item>
          <s-icon type="dark_mode" slot="icon"></s-icon>
          <div slot="text">Secondary</div>
          <s-badge slot="badge"></s-badge>
        </s-tab-item> -->
      </s-tab>

      <s-button onclick="test()">删除</s-button>
      <s-button onclick="add()">添加</s-button>

      <s-tab mode="fixed" onchange="console.log(this.selectedIndex)">
        <s-tab-item selected="true">
          <div slot="text">destination</div>
        </s-tab-item>
        <s-tab-item>
          <div slot="text">navigation</div>
          <s-badge slot="badge">16</s-badge>
        </s-tab-item>
        <s-tab-item>
          <div slot="text">container</div>
        </s-tab-item>
        <s-tab-item>
          <div slot="text">Secondary</div>
          <s-badge slot="badge"></s-badge>
        </s-tab-item>
      </s-tab>
    </main>
  </s-page>
  <script type="module" src="../dist/main.js"></script>
  <script type="module" src="./scripts/default.js"></script>
  <script>
    const tab = document.querySelector('s-tab')
    function test() {
      tab.removeChild(tab.options[tab.options.length - 1])
      setTimeout(() => {
        tab.options[tab.options.length - 1].selected = true
      }, 0)
    }

    function add() {
      const item = document.createElement('s-tab-item')
      console.log('创建item完毕')
      item.innerHTML = '<div slot="text">destination</div>'
      item.selected = true
      console.log('设置item selected')
      tab.appendChild(item)
      const item2 = document.createElement('s-tab-item')
      item2.innerHTML = '<div slot="text">destination2</div>'
      tab.appendChild(item2)
    }
  </script>
</body>

</html>